<template>
  <div>
    <button @click="cratePromise">创建一个promise</button>
  </div>
</template>

<script>
  export default {
    name: 'Promise',
    methods:{
      cratePromise() {
        let promise = new Promise((resolve, reject) => {
          setTimeout(()=>{
            const random = Math.floor(Math.random() * 10);
            random > 5 ? resolve('sucess') : reject('error')
          },0)
        });
        promise.then(res => {
          console.log(res)
        }).catch(err => {
          console.log(err)
        })
        let p1 = Promise.resolve('我是成功的Promise');
        console.log(p1);
      }
    }
  }
</script>

<style scoped lang="scss">

</style>
